const mutations = {
  //获取更新购物车列表数据
  updateCartList(state, payload) {
    state.cartList = payload.list;
  },
  //获取更新订单列表数据
  updateOrderList(state, payload) {
    state.orderList = payload.list;
  },
  updateCartDetailList(state, payload) {
    state.cartDetailList = payload.list;
    // console.log(state.cartDetailList);
    // 更新购物车数据库列表
    state.cartList = [];
    state.cartDetailList.forEach((value) => {
      state.cartList.push({
        productId: value.productId,
        productNum: value.productNum,
      });
    });
  },
  deleteCartDetailList(state) {
    //删除购物车下单物品
    let arr = state.cartDetailList.filter((val) => {
      if (!val.pChecked) {
        return val;
      }
    });
    state.cartDetailList = arr;
    // 更新购物车数据库列表
    state.cartList = [];
    state.cartDetailList.forEach((value) => {
      state.cartList.push({
        productId: value.productId,
        productNum: value.productNum,
      });
    });
  },
  // 全选功能
  checkAll(state, playload) {
    // console.log(playload);
    state.cartDetailList.forEach((value) => {
      value.pChecked = playload.pchecked;
    });
  },
};

export default mutations;
